'use strict';

const { Service } = require('egg');
class RoleService extends Service {
  // 添加role
  async createRole (info) {
    const { ctx, app } = this;
    try {
      const result = await app.mysql.insert('role', info); // 给list表新增一条数据
      return result;
    } catch (error) {
      console.log(error);
      return null;
    }
  }
  // 编辑
  async editRole (id, roleName, roleApi, roleType, instruction) {
    const { ctx, app } = this;
    try {
      const result = await app.mysql.update('role', { roleName, roleApi, roleType, instruction }, {
        where: {
          id
        }
      });
      return result;
    } catch (error) {
      console.log(error);
      return null;
    }
  }
  async deleteRole (id) {
    const { app } = this;
    try {
      const result = app.mysql.delete('role', {
        id,
      });
    } catch (error) {
      return null;
    }
  }
}
module.exports = RoleService;
